package com.flyoil.petromp.adapter.adapter_service;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cnpc.fyimageloader.glide.GlideHelper;
import com.flyoil.petromp.R;
import com.flyoil.petromp.adapter.adapter_notice.ItemNoticeAdapter;
import com.flyoil.petromp.base.BaseRecyAdapter;
import com.flyoil.petromp.entity.entity_service.ProjectServiceEntity;

/**
 * Created by songzhiyin on 2017/11/2.
 * 物资和服务的adapter
 */
public class ItemProjectServiceAdapter extends BaseRecyAdapter<ItemProjectServiceAdapter.ViewHoder, ProjectServiceEntity> {
    public ItemProjectServiceAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHoder(mInflater.inflate(R.layout.item_project_service_adapter, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHoder viewHoder = (ViewHoder) holder;
        final ProjectServiceEntity entity = getItemData(position);
        viewHoder.tv_name.setText(entity.getName());
        viewHoder.tv_type.setText(entity.getType());
        if (entity.getImgUrl().length() > 0) {
            viewHoder.img_icon.setVisibility(View.VISIBLE);
            viewHoder.img_icon_small.setVisibility(View.GONE);
            GlideHelper.showImage(mContext, entity.getImgUrl(), viewHoder.img_icon, R.mipmap.img_service_loading_error_icon);
        } else {
            viewHoder.img_icon.setVisibility(View.GONE);
            viewHoder.img_icon_small.setVisibility(View.VISIBLE);
        }
        viewHoder.line.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.Onclick(position, entity);
                }
            }
        });
    }

    class ViewHoder extends RecyclerView.ViewHolder {
        private TextView tv_name;
        private TextView tv_type;
        private ImageView img_icon;
        private ImageView img_icon_small;
        private LinearLayout line;

        public ViewHoder(View itemView) {
            super(itemView);
            tv_name = itemView.findViewById(R.id.tv_item_project_service_adapter_name);
            tv_type = itemView.findViewById(R.id.tv_item_project_service_adapter_type);
            img_icon = itemView.findViewById(R.id.img_item_project_service_adapter);
            line = itemView.findViewById(R.id.line_item_project_service_adapter);
            img_icon_small = itemView.findViewById(R.id.img_item_project_service_adapter_icon);
        }
    }
}
